import java.util.PriorityQueue;

public class Solution1738 {
    public int kthLargestValue(int[][] matrix, int k) {
        int[][] f=new int[matrix.length+1][matrix[0].length+1];
        PriorityQueue<Integer> queue=new PriorityQueue<>((a,b)->b-a);
        for (int i=0;i<matrix.length;i++){
            for (int j=0;j<matrix[0].length;j++){
                f[i+1][j+1]=f[i+1][j]^f[i][j+1]^f[i][j]^matrix[i][j];
                queue.add(f[i+1][j+1]);
            }
        }
        for (int i=0;i<k-1;i++){
            queue.poll();
        }
        return queue.poll();
    }

    public static void main(String[] args) {
        System.out.println(new Solution1738().kthLargestValue(new int[][]{{5,2},{1,6}},1));
    }
}
